﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.AttributeHelperEngine
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  internal class AttributeHelperEngine
  {
    [RequiredByNativeCode]
    private static System.Type GetParentTypeDisallowingMultipleInclusion(System.Type type)
    {
      System.Type multipleInclusion = (System.Type) null;
      for (; type != null && type != typeof (MonoBehaviour); type = type.BaseType)
      {
        if (Attribute.IsDefined((MemberInfo) type, typeof (DisallowMultipleComponent)))
          multipleInclusion = type;
      }
      return multipleInclusion;
    }

    [RequiredByNativeCode]
    private static System.Type[] GetRequiredComponents(System.Type klass)
    {
      List<System.Type> typeList = (List<System.Type>) null;
      System.Type baseType;
      for (; klass != null && klass != typeof (MonoBehaviour); klass = baseType)
      {
        RequireComponent[] customAttributes = (RequireComponent[]) klass.GetCustomAttributes(typeof (RequireComponent), false);
        baseType = klass.BaseType;
        foreach (RequireComponent requireComponent in customAttributes)
        {
          if (typeList == null && customAttributes.Length == 1 && baseType == typeof (MonoBehaviour))
            return new System.Type[3]
            {
              requireComponent.m_Type0,
              requireComponent.m_Type1,
              requireComponent.m_Type2
            };
          if (typeList == null)
            typeList = new List<System.Type>();
          if (requireComponent.m_Type0 != null)
            typeList.Add(requireComponent.m_Type0);
          if (requireComponent.m_Type1 != null)
            typeList.Add(requireComponent.m_Type1);
          if (requireComponent.m_Type2 != null)
            typeList.Add(requireComponent.m_Type2);
        }
      }
      return typeList?.ToArray();
    }

    private static int GetExecuteMode(System.Type klass)
    {
      if (klass.GetCustomAttributes(typeof (ExecuteAlways), false).Length != 0)
        return 2;
      return klass.GetCustomAttributes(typeof (ExecuteInEditMode), false).Length != 0 ? 1 : 0;
    }

    [RequiredByNativeCode]
    private static int CheckIsEditorScript(System.Type klass)
    {
      for (; klass != null && klass != typeof (MonoBehaviour); klass = klass.BaseType)
      {
        int executeMode = AttributeHelperEngine.GetExecuteMode(klass);
        if (executeMode > 0)
          return executeMode;
      }
      return 0;
    }

    [RequiredByNativeCode]
    private static int GetDefaultExecutionOrderFor(System.Type klass)
    {
      DefaultExecutionOrder customAttributeOfType = AttributeHelperEngine.GetCustomAttributeOfType<DefaultExecutionOrder>(klass);
      return customAttributeOfType == null ? 0 : customAttributeOfType.order;
    }

    private static T GetCustomAttributeOfType<T>(System.Type klass) where T : Attribute
    {
      System.Type attributeType = typeof (T);
      object[] customAttributes = klass.GetCustomAttributes(attributeType, true);
      return customAttributes != null && customAttributes.Length != 0 ? (T) customAttributes[0] : default (T);
    }
  }
}
